//
//  UIImage+TennisTintColor.m
//  CoolTennisBall
//
//  Created by wsl on 15/12/26.
//  Copyright © 2015年 CoolLang. All rights reserved.
//

#import "UIImage+TennisTintColor.h"

@implementation UIImage (TennisTintColor)

- (UIImage *) imageWithTintColor:(UIColor *)tintColor alpha:(CGFloat)alpha
{
    return [self imageWithTintColor:tintColor blendMode:kCGBlendModeDestinationIn alpha:alpha];
}

- (UIImage *) imageWithTintColor:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha {
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0.0f);
    [tintColor setFill];
    CGRect bounds = CGRectMake(0, 0, self.size.width, self.size.height);
    UIRectFill(bounds);
    if (alpha < 0 || alpha > 1) {
        alpha = 1.0;
    }
    //Draw the tinted image in context
    [self drawInRect:bounds blendMode:blendMode alpha:alpha];
    if (blendMode != kCGBlendModeDestinationIn) {
        [self drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:alpha];
    }
    UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return tintedImage;
}


@end
